import java.util.Stack;

public class SolutionOffer9 {

    Stack<Integer> s1;
    Stack<Integer> s2;

    public SolutionOffer9() {
        s1=new Stack<>();
        s2=new Stack<>();
    }

    public void appendTail(int value) {
        s1.push(value);
    }

    public int deleteHead() {
        if (s1.isEmpty()&&s2.isEmpty()){
            return -1;
        }
        if (s2.isEmpty()){
            while (!s1.isEmpty()){
                s2.push(s1.pop());
            }
        }
        return s2.pop();
    }

    public static void main(String[] args) {
        SolutionOffer9 solutionOffer9=new SolutionOffer9();
        solutionOffer9.appendTail(3);
        System.out.println(solutionOffer9.deleteHead());
        System.out.println(solutionOffer9.deleteHead());
    }
}
